package com.example.neusoft.zyfypt_wk.model;


import com.example.neusoft.zyfypt_wk.bean.VideoBean;
import com.example.neusoft.zyfypt_wk.iface.VideoListener;
import com.example.neusoft.zyfypt_wk.iface.Videoiface;
import com.example.neusoft.zyfypt_wk.service.VideoSpecialService;
import com.example.neusoft.zyfypt_wk.service.VideoUpdateService;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by Neusoft on 2017/4/20.
 */
//model  获取数据
public class VideoUpdateModel implements Videoiface {
    private Retrofit retrofit;
    private String BASEURL
            ="http://amicool.neusoft.edu.cn/";
     //构造函数
    public VideoUpdateModel()
    {   //使用Retrofit----1
        retrofit=new Retrofit.Builder()
                .baseUrl(BASEURL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }

    //获取数据
    @Override
    public void getResultList(String mod, int page, String sessionID, final VideoListener listener) {
        //使用Retrofit----2
        VideoUpdateService service
                =retrofit.create(VideoUpdateService.class);
        Call<List<VideoBean>> call
                = service.getResult(mod,page,sessionID);
        //使用Retrofit----3
        call.enqueue(new Callback<List<VideoBean>>() {
            @Override
            public void onResponse(Call<List<VideoBean>> call, Response<List<VideoBean>> response) {
                if(response.isSuccessful() && response!=null)
                {  listener.onResponse(response.body());
                }
                else   listener.onFail("onresponse fail");
            }
            @Override
            public void onFailure(Call<List<VideoBean>> call, Throwable t) {
                listener.onFail(t.toString());
            }
        });



    }
}
